class Solution
{
public:
    string reverseWords(string s)
    {
        stringstream ssin(s);
        vector<string> words;
        string word;
        while (ssin >> word)
        {
            words.push_back(word);
        }
        stringstream ssout;
        for (int i = words.size() - 1; i > 0; --i)
        {
            ssout << words[i] << " ";
        }
        ssout << words[0];
        return ssout.str();
    }
};